package com.syc.legou.dataImport;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.syc.legou.dataImport.mapper.VodMapper;
import com.syc.legou.dataImport.service.impl.VodServiceImpl;
import com.syc.legou.legou_search_api.entity.Vod;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class testImport {
    @Autowired
    private VodMapper vodMapper;

    @Autowired
    private VodServiceImpl vodService;

    @Autowired
    private SolrTemplate solrTemplate;

    @Test
    public void test01() {
        Page<Vod> page = new Page<>(1, 10);
        Integer integer = vodMapper.selectCount(null);
        System.out.println(integer);
    }

    @Test
    public void test02() {
        Integer total = vodService.count(null);
        Integer pageSize = 50;
        Integer pageCount = (total + pageSize - 1) / pageSize;

        for (int i = 99; i <= pageCount; i++) {
            Page<Vod> page = new Page<>(i, pageSize);
            vodService.page(page, null);
            solrTemplate.saveBeans("collection1", page.getRecords());
            solrTemplate.commit("collection1");
        }
    }

}
